<?php
use Fastknife\Service\ClickWordCaptchaService;
use Fastknife\Service\BlockPuzzleCaptchaService;

if (!function_exists('aj_captcha_create')) {
    /**
     * 创建验证码
     * @return array
     */
    function aj_captcha_create(string $captchaType)
    {
        return aj_get_serevice($captchaType)->get();
    }
}

if (!function_exists('aj_get_serevice')) {

    function aj_get_serevice(string $captchaType)
    {
        $config = config('ajcaptcha');
        switch ($captchaType) {
            case "clickWord": // 文字点击
                $service = new ClickWordCaptchaService($config);
                break;
            case "blockPuzzle": // 滑动拼图
                $service = new BlockPuzzleCaptchaService($config);
                break;
            default:
                throw new \Exception('captchaType参数不正确：'.$captchaType);
        }
        return $service;
    }
}

if (!function_exists('aj_captcha_check_one')) {
    /**
     * 验证滑块1次验证
     * @param string $token
     * @param string $pointJson
     * @return bool
     */
    function aj_captcha_check_one(string $captchaType, string $token, string $pointJson)
    {
        aj_get_serevice($captchaType)->check($token, $pointJson);
        return true;
    }
}